package com.wondream.myframework.app.vo.base;

import com.github.pagehelper.Page;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.List;

@Data
@ToString
@NoArgsConstructor
public class ListInfo<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    protected long total;
    protected List<? extends T> list;

    public ListInfo(List<? extends T> list) {
        this.list = list;
        if (list instanceof Page) {
            this.total = ((Page) list).getTotal();
        } else {
            this.total = (long) list.size();
        }

    }

    public static <T> ListInfo<T> of(List<? extends T> list) {
        return new ListInfo(list);
    }

}

